import type { CategoryCreateDto, CategoryUpdateDto, CategoryListDto, CategorySingleDto } from "@/dtos/category.dto";
import type { PageRequest } from "@/types";
import http from "@/utils/http";

/**
 * 获取分类列表
 * @param params - 分页参数
 * @returns 包含分类列表、总数和总页数的对象
 */
export function getCategoryListApi(params: PageRequest) {
  return http.get<any, { list: CategoryListDto[]; total: number; pages: number }>("/categories", { params });
}

/**
 * 获取单个分类
 * @param categoryId - 分类ID
 * @returns 分类的详细信息
 */
export function getCategoryApi(categoryId: string) {
  return http.get<any, CategorySingleDto>(`/categories/${categoryId}`);
}

/**
 * 创建分类
 * @param data - 分类创建数据
 * @returns 创建成功的布尔值
 */
export function createCategoryApi(data: CategoryCreateDto) {
  return http.post<any, boolean>("/categories", data);
}

/**
 * 更新分类
 * @param categoryId - 分类ID
 * @param data - 分类更新数据
 * @returns 更新成功的布尔值
 */
export function updateCategoryApi(categoryId: string, data: CategoryUpdateDto) {
  return http.put<any, boolean>(`/categories/${categoryId}`, data);
}

/**
 * 删除分类
 * @param categoryId - 分类ID
 * @returns 删除成功的布尔值
 */
export function deleteCategoryApi(categoryId: string) {
  return http.delete<any, boolean>(`/categories/${categoryId}`);
}